<?php

namespace App\Services\SetGoldBudget;

use Carbon\Carbon;
use App\Models\GoldRound;
use App\Http\Controllers\Api\V1\Requests\FormRequest;

class CheckFromGoldBudgetRequest extends FormRequest
{
	public function rules()
	{
		return [
			'rid' => [
				'required',
				'integer',
				'min:1',
				$this->rid(),
			]
		];
	}
	
	public function attributes()
	{
		return [
			'rid' => '场次',
		];
	}
	
	public function rid()
	{
		return function ($key, $value, $fail) {
			
			$rid = $this->rid;
			
			$time = Carbon::now();
			
			if ($time->lt(GoldRound::todayOpenedAt($rid))) {
				return $fail('本场尚未入场');
			} elseif ($time->gt(GoldRound::todayEndedAt($rid))) {
				return $fail('本场已经结束');
			}
			
			return true;
		};
	}
}
